package com;

import com.common.Constant;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.RestTemplate;


@SpringBootApplication
@ServletComponentScan
@EnableScheduling
public class App implements EmbeddedServletContainerCustomizer{
	public static void main(String[] args) {
		Constant.ctx=SpringApplication.run(App.class,args);
	}
	@Bean
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}

	@Bean
	public AsyncRestTemplate asyncRestTemplate() {
		HttpComponentsAsyncClientHttpRequestFactory httpRequestFactory = new HttpComponentsAsyncClientHttpRequestFactory();
		httpRequestFactory.setReadTimeout(10000);//等待最大值.
		httpRequestFactory.setConnectTimeout(5000);
		AsyncRestTemplate restTemplate=new AsyncRestTemplate(httpRequestFactory);
		return restTemplate;
	}
	@Override
	public void customize(ConfigurableEmbeddedServletContainer config) {
		config.setPort(9991);
	}
	
}
